package com.jt.tenant.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.adapter.ReportListItemAdapter;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetFaultListById;
import com.jt.tenant.widget.Tools;
import com.zcx.helper.http.AsyCallBack;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/2/16.
 */
public class DiagnosticReportActivity extends JTActivity{

    private GetFaultListById getFaultListById;

    private ReportListItemAdapter mAdapter;

    private ListView mListView;

    private TextView mReportTimeText;

    private List<GetFaultListById.Info> mList = new ArrayList<>();

    private String Time;

    private String Score;

    private String State;

    private String Id;



    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_diagnostic_report);

        getBundleDate();

        initView();

        getFaultListById = new GetFaultListById(new AsyCallBack<List<GetFaultListById.Info>>(){
            @Override
            public void onSuccess(String toast, int type, List<GetFaultListById.Info> infos) throws Exception {
                super.onSuccess(toast, type, infos);
                if(toast.equals("000")&&infos.size()>0){
                    mList.addAll(infos);

                    mAdapter.notifyDataSetChanged();
                }else{
//                    Toast.makeText(DiagnosticReportActivity.this, "暂无故障列表", Toast.LENGTH_SHORT).show();
                }



            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);

            }
        });
        getFaultListById.id = Id;
        getFaultListById.execute(this);

    }

    private void getBundleDate(){
        Intent intent = getIntent();

        Bundle bundle = intent.getExtras();

        Time = bundle.getString("scoreDate");

        Score = bundle.getString("score");

        Id = bundle.getString("id");

        State = bundle.getString("state");
    }

    private void initView(){

        ((TextView)findViewById(R.id.tv_title_name)).setText("诊断报告");

        mListView = (ListView) findViewById(R.id.report_list);

        mListView.setDividerHeight(JTApplication.ScaleScreenHelper.getWidthHeight(12));

        mAdapter = new ReportListItemAdapter(this,mList);

        mListView.setAdapter(mAdapter);

        mReportTimeText = (TextView) findViewById(R.id.report_time_text);

        mReportTimeText.setText(Tools.getTime1(Time));

    }

}
